from openpyxl import load_workbook
from openpyxl import Workbook
import os
import glob

workbookAll = Workbook()
sheet = workbookAll.active
sheet.title = '汇总各个支行数据'
first_line_header = ['支行', '网点', '当日金额']
sheet.append(first_line_header)
# data_select = []


def get_data_from_each_xls(each_sheet):
    data_sheet = []
    for row in each_sheet.iter_rows(min_row=2):
        data_list = []
        for cell in row:
            data_list.append(cell.value)
        data_sheet.append(data_list)
    return data_sheet


def gather_data2_new_workbook(workbook_all, data_from_sheet):
    for row in data_from_sheet:
        workbook_all.active.append(row)


# print(glob.glob('汇总*.xlsx'))
for filename in glob.glob('汇总*.xlsx'):
    workbook = load_workbook(filename=filename)
    data_each_sheet = get_data_from_each_xls(workbook.active)
    print(data_each_sheet)

    gather_data2_new_workbook(workbookAll, data_each_sheet)
    # print(workbook)

workbookAll.save(filename='汇总各个支行数据.xlsx')
